@echo off

set hour=%time:~0,2%
if "%time:~0,1%"==" " set hour=0%time:~1,1%
set now=%Date:~0,4%%Date:~5,2%%Date:~8,2%%hour%%Time:~3,2%%Time:~6,2%

echo %now%

set host=192.168.0.10
set port=3306
set dbname=kcb_cms
set backupfile=E:\backup\%dbname%-%now%.sql

:: 导出表结构和数据到 sql 文件
"D:\phpstudy_pro\Extensions\MySQL5.7.26\bin\mysqldump" -h%host% -P%port% -c --add-drop-table %dbname% > %backupfile%

echo delete files before 10 days
:: 暂时不用，好像有点问题
:: forfiles /p "E:\backup" /m *.sql /d -10 /c "cmd /c del @file"

:: 在指定的数据库中，导入 sql 文件中的语句并执行
"D:\phpstudy_pro\Extensions\MySQL5.7.26\bin\mysql" %dbname% < %backupfile%

:: 脚本执行完不自动关闭窗口
pause
